package com.hkrt.arch;

import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.ViewModel;

/**
 *
 * @author chenjinguang
 * @date 20.05.2017
 */

public final class BaseViewModel<V extends BaseMVPContract.View, P extends BaseMVPContract.Presenter<V>>
        extends ViewModel {

    private P presenter;

    void setPresenter(P presenter) {
        if (this.presenter == null) {
            this.presenter = presenter;
        }
    }

    P getPresenter() {
        return this.presenter;
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if(presenter != null){
            presenter.onPresenterDestroy();
            presenter = null;
        }
    }
}
